function showKnowledgeBaseSearch() {   
	window.location.href = "showKnowledgeBaseSearch.do";
}

function ajaxFindKnowledgeBaseSearchList(currentPage,pageSize) {
	$.ajax({
		type : "post",
		url : "ajaxKnowledgeBaseSearchList.do",
		data : {
			deviceNum : $("#deviceNum").val(),
			currentPage:currentPage,
			pageSize:pageSize,
		},
		success : function(msg) {
			$("#listKnowledgeBaseBox").html(msg);
		}
	});
}

function ajaxShowKnowledgeBaseEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowKnowledgeBaseEdit.do",
		data:{knowledgeBaseId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 690,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveKnowledgeBase(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}


function ajaxSaveKnowledgeBase(objDialog) {
	knowledgeBaseValidate();
	if ($("#frmKnowledgeBase").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveKnowledgeBase.do",
				success: function (msg) {
					clearInput("#sltKnowledgeBase");
					showMessageDialog("保存知识库信息","知识库信息保存成功。",null,dialogType.info);
					ajaxFindKnowledgeBaseSearchList();
				}
		};
		$("#frmKnowledgeBase").ajaxSubmit(options);
	}
}

function ajaxShowKnowledgeBaseView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowKnowledgeBaseView.do",
		data:{knowledgeBaseId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 690,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxDeleteKnowledgeBaseById(id) {
	var KnowledgeBaseIds="";
	var sltEQPT = $("#listKnowledgeBaseList tbody input:checked").length;
	if(id==null){
		$("#listKnowledgeBaseList tbody input:checked").each(function(){ 
			KnowledgeBaseIds += $(this).val()+";";
		});
		if(sltEQPT == 0){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			KnowledgeBaseIds = KnowledgeBaseIds.substring(0, KnowledgeBaseIds.length-1);
		} 
	}else{
		KnowledgeBaseIds=id;
		sltEQPT = 1;
	}
	if( KnowledgeBaseIds!=null){
		showMessageDialog("删除知识库信息","确定要删除所选“"+sltEQPT+"”条知识库信息记录吗？",
				function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeleteKnowledgeBaseByIds.do",
				data:{KnowledgeBaseIds:KnowledgeBaseIds},
				success:function(msg){
					ajaxFindKnowledgeBaseSearchList();
					showMessageDialog("提示","知识库信息删除成功",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}

function knowledgeBaseValidate(){
	$("#frmKnowledgeBase").validate({
		errorLabelContainer: $("#infoKnowledgeBase"),
		rules : {
			title : {
				required :true				
			},
			description : {
				required :true				
			},
			attachment : {
				required :true				
			}
		},
		messages : {
			title : {
				required :"请输入标题！"
			},
			description : {
				required :"请输入说明！"
			},
			attachment : {
				required :"请添加附件！"
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}